package indi.zhang.common.exception;

import indi.zhang.common.base.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.HandlerMethod;

@Slf4j
@ControllerAdvice
public class BusinessExceptionHandler {

    @ResponseBody
    @ExceptionHandler(ServiceException.class)
    public Result globalException(HandlerMethod method, ServiceException ex) {
        log.info("GlobalExceptionHandler...");
        return Result.error(ex.getMessage());
    }
}
